
// 更新驱动实时状态
function refreshDriverRunning() {
	var title = ''
	title += "<li class='list-group-item'>";
	title += "<div class='row'>";
	title += "<div class='col-md-2'>序号</div>";
	title += "<div class='col-md-10'>名称</div>";
	title += "</div>";
	title += "</li>";

	// 获取正在运行的驱动列表
	$.post($basePath + "/index/getRunning", function(runData) {
		if (runData.success == true) {
			showDriverRunning(runData.resultValue, title);
		} else {
			// 如果请求失败
			bootGrowl(data.resultValue, "danger");
		}
	});

	// 获取正在排队的驱动列表
	$.post($basePath + "/index/getQueue", function(queueData) {
		if (queueData.success == true) {
			// 渲染驱动排队列表
			showDriverQueneg(queueData.resultValue, title);
		} else {
			// 如果请求失败
			bootGrowl(data.resultValue, "danger");
		}
	});
}
// 加载正在运行的驱动实时运行状态监控数据
function showDriverRunning(runningQuene, title) {
	var ul = $("#runningGround");
	// 清空历史数据
	ul.html("");
	var html = title;
	// 渲染标题

	var dataLen = runningQuene.length;
	for (var i = 0; i < dataLen; i++) {
		html += "<li class='list-group-item'>";
		html += "<div class='row'>";
		html += "<div class='col-md-2'>" + (i + 1) + "</div>";
		html += "<div class='col-md-10'>" + runningQuene[i] + "</div>";
		html += "</div>";
		html += "</li>";
	}
	ul.html(html);
}

// 加载正在排队的驱动实时运行状态监控数据
function showDriverQueneg(quene, title) {
	var ul = $("#queneGround");
	// 清空历史数据
	ul.html("");
	var html = title;
	var dataLen = quene.length;
	for (var i = 0; i < dataLen; i++) {
		html += "<li class='list-group-item'>";
		html += "<div class='row'>";
		html += "<div class='col-md-2'>" + (i + 1) + "</div>";
		html += "<div class='col-md-10'>" + quene[i] + "</div>";
		html += "</div>";
		html += "</li>";
	}
	ul.html(html);
}

$(function() {

	// 更新驱动实时状态
	refreshDriverRunning();

	// $$monitorFreshRunningIntervalStarted变量防止$initContainer.load($basePath+'/index');加载后，导致定时任务刷新JS被重复执行
	// 页面实时刷新测试
	if(!$monitorFreshRunningIntervalStarted){
		// 驱动列表实时刷新
		setInterval('refreshDriverRunning()', 10000);
		$monitorFreshRunningIntervalStarted = true;
	}

});